// import express, { Request, Response } from "express";
// import type { UserRequest, UserResponse } from "./types";
// import { HelloController } from "./HelloController";

// const app = express();
// app.use(express.json());

// new HelloController();

// app.get("/", (req: Request, res: Response) => {
//   res.send("Hello World!");
// });

// app.post("/users", (req: UserRequest, res: UserResponse) => {
//   console.log(req.body);
//   res.json({ user: req.body });
// });

// app.listen(3000, () => {
//   console.log("Example app listening on port 3000!");
// });

import { startServer } from "./decorator";
import "./controller/HelloController";
import "./controller/FileController";
import Hello2Controller from "./controller/Hello2Controller";
import "./DefaultBeanPostProcessor";
import { Autowired, Component, init, singletonObjects } from "./ioc";

/**
 * TypeScript 装饰器
 * https://juejin.cn/post/7366441097583984680
 */
@Component()
class App {
  @Autowired()
  private helloController: Hello2Controller;

  constructor(helloController: Hello2Controller) {
    console.log("App constructor");
    this.helloController = helloController;
  }

  start() {
    console.log("App start");
    if (this.helloController) {
      this.helloController.hello2();
    }
  }
}

init()
  .then(() => {
    // 确保所有装饰器执行完毕后再调用 initAfterDecorators
    const app = singletonObjects.get("App");
    if (app) {
      // 启动应用程序的逻辑
      console.log("App started:", app);
      // startServer(undefined , ".env.prod");
      startServer();
      (app as App).start();
    } else {
      console.error("App not found in singletonObjects");
    }
  })
  .catch((error) => {
    console.error("Initialization failed:", error);
  });
